package IO_Stream_Test;

import java.io.*;

public class Test
{
	public static void main(String[] args) throws IOException
	{
		boolean ret = Copy_File("./img/cf338ce02b19ab6b1ad8bc421bd8095b.png", "./Copy_img/1.png");
		System.out.println("文件复制结果:" + ret);
	}

	static void Output_Stream_Test() throws IOException
	{
		//第二个选项为追加选项,打开文件不清空文件内容
		OutputStream outputsteam = new FileOutputStream("./1.txt", true);
		//OutputStream outputsteam = new FileOutputStream("./1.txt");
		byte[] writeBuffer = new byte[1024];
		writeBuffer = "hello, OutputStream\n".getBytes();
		outputsteam.write(writeBuffer);
		outputsteam.write("hello, OutputStream".getBytes());
	}

	static void Input_Stream_Test() throws IOException
	{
		InputStream inputstream = new FileInputStream("./1.txt");
		byte[] readBuffer = new byte[1024];
		int read = inputstream.read(readBuffer);
		System.out.println(read);
	}

	static Boolean Copy_File(String src, String dest)
	{
		try
		{
			InputStream in = new FileInputStream(src);
			OutputStream out = new FileOutputStream(dest);
			byte[] Buffer = new byte[1024];
			while(in.read(Buffer) != -1)
			{
				out.write(Buffer);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
